package nezumi.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.LinkedList;

import nezumi.state.State;

public class PathEntity extends AEntity {

	private final static int PATH_WIDTH = 4;

	public PathEntity(State state, Component enclosingComp) {
		super(state, enclosingComp);
	}

	/**
	 * Draw the current path in green color.
	 */
	@SuppressWarnings("unchecked")
	public void draw(Graphics2D g) {

		final LinkedList<Point> path = (LinkedList<Point>) state.getPlanner()
				.getPath().clone();

		final Color oldColor = g.getColor();
		g.setColor(Color.BLUE);

		for (Point p : path) {
			Point p2 = this.translatePoint(p);
			g.fillRect(p2.x - PATH_WIDTH / 2, Math.abs(p2.y - PATH_WIDTH / 2),
					PATH_WIDTH, PATH_WIDTH);
		}
		// restore the old color
		g.setColor(oldColor);
	}
}
